/**
 * 
 */
package ve.com.neometrica.inventario.impl.dao;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import ve.com.neometrica.inventario.api.dao.DestinoDao;
import ve.com.neometrica.inventario.api.model.Destino;

/**
 * @author a.cabrera
 *
 */
public class DestinoDaoImpl extends HibernateDaoSupport implements DestinoDao {

	/* (non-Javadoc)
	 * @see ve.com.neometrica.inventario.api.dao.DestinoDao#getAll()
	 */
	@Override
	public List<Destino> getAll() {
		return getHibernateTemplate().loadAll(Destino.class);
	}

	/* (non-Javadoc)
	 * @see ve.com.neometrica.inventario.api.dao.DestinoDao#save(ve.com.neometrica.inventario.api.model.Destino)
	 */
	@Override
	public void save(Destino destino) {
		if(destino.getId()==null){
			this.getHibernateTemplate().save(destino);
		}else{
			this.getHibernateTemplate().saveOrUpdate(destino);
		}
	}

	/* (non-Javadoc)
	 * @see ve.com.neometrica.inventario.api.dao.DestinoDao#getById(java.lang.Integer)
	 */
	@Override
	public Destino getById(Integer id) {
		try{
			return getHibernateTemplate().load(Destino.class, id);
		}catch (Exception e) {
			return null;
		}
	}

}
